﻿//-----------------------------------------------------------------------
// <copyright file="LoadableServiceAttribute.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Services.SDK.Services.Interfaces;

#endregion

namespace GateShift.Services.SDK.Services
{
    /// <summary>
    /// Attribute used to identify a service class that can be loaded and run
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class LoadableServiceAttribute : Attribute
    {
        private readonly Type _serviceType;

        /// <summary>
        /// Initializes a new instance of the LoadableServiceAttribute class
        /// </summary>
        /// <param name="serviceType">IService related type that can be handled by this type</param>
        public LoadableServiceAttribute(Type serviceType)
        {
            if (!typeof(IService).IsAssignableFrom(serviceType))
            {
                throw new ArgumentException("ServiceType must be assignable to IService", "serviceType");
            }

            if (typeof(IService) == serviceType)
            {
                throw new ArgumentException("IService is an abstract form of the service. Create an inheriting interface first.", "serviceType");
            }

            _serviceType = serviceType;
        }

        /// <summary>
        /// Gets the base interface type for the service that can be handled
        /// </summary>
        public Type ServiceType
        {
            get
            {
                return _serviceType;
            }
        }
    }
}